require.config({
    baseUrl:"./modules",
    paths:{
        jq:"../libs/jquery",
        getData:"getData",
        render:"detailRender",
        addList:"addList",
        Magnifier:"Magnifier"
    }
})


require(["jq","getData","render","addList","Magnifier"],function(_,getData,render,addList,Magnifier){
    const url = "http://localhost:3000/api?type=getGoods";
     // 页面的登录守卫
     if (localStorage.getItem("token") !== "ok") {
        location.href = "./login.html"
    }
    // 获取地址栏的id
    const id = location.search.split("=")[1];

    getData(url).then((res)=>{
        // console.log(res)
        // 查询到真实要渲染的商品数据
        let i = 0;
        res.some((val,idx)=>{
            i = idx;
            return val.proId === id;
        })

        // 根据数据渲染到指定容器
        render(res[i]);

        // 点击加入购物车
        $(".purchase").find(".join").click(function(){
            // 调用添加购物车模块功能
            addList($(this));
        })


        // 执行放大镜模块
        new Magnifier({
            left:document.getElementById("left"),
            right:document.getElementById("right"),
            sBspan:document.querySelector(".smlbox span"),
            sBox:document.querySelector(".smlbox"),
            bBox:document.querySelector(".bigimg"),
            sBimg:document.querySelector(".smlbox img"),
            bBimg:document.querySelector(".bigimg img"),
            imgBox:document.querySelector(".magnifier"),
            imgs:document.querySelectorAll(".magnifier li img")
        })
    
    })
})



